package com.jphoebe.plugin.mybatis.form;

import cn.hutool.setting.Setting;
import com.intellij.openapi.components.ServiceManager;
import com.jphoebe.plugin.mybatis.bean.setting.GlobalSetting;
import com.jphoebe.plugin.mybatis.service.setting.GlobalSettingService;
import com.jphoebe.plugin.mybatis.utils.Il8nUtil;
import lombok.Data;

import javax.swing.*;

/**
 * PluginSettingForm class
 *
 * @author 蒋时华
 * @date 2019/2/18
 */
@Data
public class PluginSettingForm {

    /*** main panel */
    private JPanel mainPanel;

    /*** setting panel */
    private JPanel pluginSettingPanel;
    /*** label */
    private JLabel openNaviJumpLabel;
    private JLabel naviLogoLabel;
    /*** 打开 跳转导航按钮显示 */
    private JRadioButton openNaviJumpButton;
    /*** 关闭 跳转导航按钮显示 */
    private JRadioButton closeNaviJumpButton;
    /*** 导航图标按钮 */
    private JComboBox naviIcon;

    /*** label */
    private JLabel lanuageTextLabel;
    /*** 语言设置 */
    private JComboBox language;

    /*** logo panel */
    private JPanel pluginSettingLogoPanel;
    /*** logo */
    private JLabel settingLogo;


    public PluginSettingForm() {
        GlobalSetting globalSetting = GlobalSettingService.getInstance().getState();
        // Radio 按钮组
        ButtonGroup naviJumpButtonGroup = new ButtonGroup();
        naviJumpButtonGroup.add(openNaviJumpButton);
        naviJumpButtonGroup.add(closeNaviJumpButton);
        // 默认显示
        this.setIl8nText(globalSetting);
    }

    public void setIl8nText(GlobalSetting globalSetting) {
        Setting currnetSysLanguage = Il8nUtil.getCurrnetSysProp(globalSetting.getLanguage());
        this.lanuageTextLabel.setText(currnetSysLanguage.getStr("setting.lanuageTextLabel"));
        this.openNaviJumpLabel.setText(currnetSysLanguage.getStr("setting.openNaviJumpLabel"));
        this.openNaviJumpButton.setText(currnetSysLanguage.getStr("setting.openNaviJumpButton"));
        this.closeNaviJumpButton.setText(currnetSysLanguage.getStr("setting.closeNaviJumpButton"));
        this.naviLogoLabel.setText(currnetSysLanguage.getStr("setting.pluginSettingPanel"));
        language.removeAllItems();
        naviIcon.removeAllItems();
        if (Il8nUtil.ZH_CN.equals(globalSetting.getLanguage())) {
            // 语言设置
            language.addItem("中文");
            language.addItem("英语");
            // 导航图片图标
            naviIcon.addItem("默认");
            naviIcon.addItem("图标1");
            naviIcon.addItem("图标2");
        } else if (Il8nUtil.EN_US.equals(globalSetting.getLanguage())) {
            // 语言设置
            language.addItem("Chinese");
            language.addItem("English");
            // 导航图片图标
            naviIcon.addItem("default");
            naviIcon.addItem("icon1");
            naviIcon.addItem("icon2");
        }
    }

}
